# coding: utf-8
from PySide6.QtCore import Signal, Qt
from PySide6.QtWidgets import QGridLayout, QWidget

from common import SingleIcon
from .type_item_card import TypeItemCard


class FirstWindow(QWidget):
    typeChanged = Signal(str)

    def __init__(self, parent=None):
        super().__init__(parent)
        self.grid = QGridLayout(self)

        self.pyinstallerCard = TypeItemCard(
            SingleIcon.Pyinstaller,
            "PyInstaller",
            "从 Python 代码创建可执行文件，支持 Windows、Linux、macOS 等多个平台。(打包较快，但体积较大，启动速度较慢)",
            self
        )
        self.nuitkaCard = TypeItemCard(
            SingleIcon.Nuitka,
            "Nuitka",
            '将 Python 代码编译成独立的可执行文件，支持 Windows、Linux、macOS 等多个平台。(打包较慢，但体积较小，启动速度较快)',
            self
        )
        self.settingCard = TypeItemCard(
            SingleIcon.Setting,
            "设置",
            '应用设置页面，用于设置应用相关信息',
            self
        )
        self.__initWidget()

    def __initWidget(self):
        self.grid.setSpacing(20)
        self.grid.setContentsMargins(50, 50, 50, 50)
        self.grid.setAlignment(Qt.AlignmentFlag.AlignCenter)
        self.grid.setColumnStretch(0, 1)
        self.grid.setColumnStretch(1, 1)
        self.grid.setRowStretch(0, 1)
        self.grid.setRowStretch(1, 1)

        self.grid.addWidget(self.pyinstallerCard, 0, 0)
        self.grid.addWidget(self.nuitkaCard, 0, 1)
        self.grid.addWidget(self.settingCard, 1, 0, 1, 2)

        self.pyinstallerCard.clicked.connect(lambda: self.typeChanged.emit("pyinstaller"))
        self.nuitkaCard.clicked.connect(lambda: self.typeChanged.emit("nuitka"))
        self.settingCard.clicked.connect(lambda: self.typeChanged.emit("setting"))